import { GetterTree } from 'vuex';

const getters: GetterTree<any, any> = {
  isLogin (state): boolean {
    return state.login;
  },

  curElement (state) {
    if (!state.curElementId) {
      return {};
    }
    return state.elementList.find(item => item.id === state.curElementId);
  },

  groups (state) {
    return state.elementList.filter(item => item.type === 'group');
  },
  groupsElementIds (state,getters) {
    let arr = [];
    for (let i of getters.groups) {
      arr = arr.concat(i.extra);
    }
    return arr;
  },
  groupsElements (state,getters) {
    return state.elementList.filter(item => getters.groupsElementIds.includes(item.id));
  },
  selectedElements (state) {
    return state.elementList.filter(item => state.selectedElementIds.includes(item.id));
  },
  selectedAndGroupElements (state,getters) {
    return getters.selectedElements.filter(item => getters.groupsElementIds.includes(item.id));
  },
  excludeSelectedElements (state) {
    return state.elementList.filter(item => !state.selectedElementIds.includes(item.id));
  },
  excludeSelectedAndGroupElements (state,getters) {
    return getters.excludeSelectedElements.filter(item => getters.groupsElementIds.includes(item.id));
  },
  excludeGroupAndSelectedElements (state,getters) {
    return getters.selectedElements.filter(item => !getters.groupsElementIds.includes(item.id));
  },
  excludeGroupAndExcludeSelectedElements (state,getters) {
    return getters.excludeSelectedElements.filter(item => !getters.groupsElementIds.includes(item.id));
  }
};

export default getters;
